package com.cain.calendar.bean;

import com.cain.calendar.tool.Constant;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by Cain on 2016/6/26.
 * 事件数据结构
 */
public class Event implements Serializable {

    private static SimpleDateFormat format = new SimpleDateFormat ("yyyy-MM-dd HH:mm");

    private int id;   //事件id
    private String name;   //事件名称
    private Date time;   //提醒时间
    private String tag;   //事件标签
    private String remark;   //备注

    public Event() {
        id = -1;
        name = "";
        time = Calendar.getInstance().getTime();
        tag = Constant.tagList.get(0);
        remark = "";
    }

    public Event(int id, String name, Date time, String tag, String remark) {
        this.id = id;
        this.name = name;
        this.time = time;
        this.tag = tag;
        this.remark = remark;
    }

    public Event(int id, String name, int year, int month, int day, int hour, int minute, String tag, String remark) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month, day, hour, minute);
        this.id = id;
        this.name = name;
        this.time = calendar.getTime();
        this.tag = tag;
        this.remark = remark;
    }

    public Event(int id, String name, String time, String tag, String remark) {
        this.id = id;
        this.name = name;
        setTime(time);
        this.tag = tag;
        this.remark = remark;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getTime() {
        return time;
    }

    public String getTimeString() {
        return format.format(time);
    }

    public void setTime(Date time) {
        this.time = time;
    }

    public void setTime(int year, int month, int day, int hour, int minute) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month, day, hour, minute);
        this.time = calendar.getTime();
    }

    public void setTime(String formatString) {
        try {
            time = format.parse(formatString);
        } catch (ParseException e) {
            e.printStackTrace();
            time = Calendar.getInstance().getTime();
        }
    }

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }
}
